package com.psychproject.web.services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.psychproject.web.domains.GroupUser;
import com.psychproject.web.domains.HelperGroup;
import com.psychproject.web.domains.User;
import com.psychproject.web.mappers.HelperGroupMapper;
import com.psychproject.web.mappers.UserMapper;

@Service
@Transactional
public class HelperGroupServices {
	@Autowired
	private HelperGroupMapper helperGroupMapper;
	@Autowired
	private UserMapper userMapper;

	public void createHelperGroup(HelperGroup helperGroup) {
		helperGroupMapper.create(helperGroup);
		for(User helper : helperGroup.getHelpers()){
			helperGroupMapper.createGroupUser(new GroupUser(helperGroup.getId(),helper.getId()));
		}
	}

	public HelperGroup findById(Long id) {
		return helperGroupMapper.findById(id);
	}
}
